package com.example.crmweb.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.example.crmweb.entity.Branch;
import com.example.crmweb.entity.Staff;
import com.example.crmweb.mapper.BranchMapper;
import com.example.crmweb.service.BranchService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author -CRM-
 * @since 2022-03-18
 */
@Service
public class BranchServiceImpl extends ServiceImpl<BranchMapper, Branch> implements BranchService {
    @Autowired
    private BranchMapper branchMapper;


    /**
     * 新增部门
     *
     * @param branch
     * @return
     */
    @Override
    public Integer createBranch(Branch branch) {
        int insert = branchMapper.insert(branch);
        return insert;
    }

    /**
     * 修改部门
     *
     * @param branch
     * @return
     */
    @Override
    public Integer modifyBranch(Branch branch) {
        int update = branchMapper.updateById(branch);
        return update;
    }

    /**
     * 删除部门
     *
     * @param id
     * @return
     */
    @Override
    public Integer deleteBranch(Integer id) {
        int delete = branchMapper.deleteById(id);
        return delete;
    }

    /**
     * 根据id查询单一部门
     *
     * @param id
     * @return
     */
    @Override
    public Optional<Branch> describeById(Integer id) {
        return Optional.of(baseMapper.selectById(id));
    }

    /**
     * 查询所有部门
     *
     * @return
     */
    @Override
    public Optional<List<Branch>> describeList() {
        return Optional.of(baseMapper.selectList(Wrappers.query()));
    }

    /**
     * 查询部门下属部门
     *
     * @param pid 上级部门id
     * @return data
     */
    @Override
    public Optional<List<Integer>> describeChildrens(Integer pid) {
        return Optional.empty();
    }

    @Override
    public Branch listss(Branch branch) {
//        QueryWrapper<Branch> branchQueryWrapper = new QueryWrapper<>();
//        branchQueryWrapper.eq("name",branch.getName());
//        Integer id = baseMapper.selectOne(branchQueryWrapper).getId();
//        QueryWrapper<Staff> staffQueryWrapper = new QueryWrapper<>();
//        QueryWrapper<Staff> id1 = staffQueryWrapper.eq("id", id);

        return null;
    }
}